// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-6-14

#ifndef __AUTOPTR_H__
#define __AUTOPTR_H__

#pragma once

//##ModelId=44CF175800D1
template<typename T>
class CJoyAutoPtr
{
protected:
	//##ModelId=44CF175800DB
    T*  m_ptr;
public:
	//##ModelId=44CF175800DC
    CJoyAutoPtr(T* ptr = NULL):
        m_ptr(ptr)
    {
    }
	//##ModelId=44CF175800DE
    ~CJoyAutoPtr()
    {
        if(m_ptr != NULL)
        {
            delete m_ptr;
        }
    }
	//##ModelId=44CF175800DF
    void Attach(T* ptr)
    {
        ASSERT(m_ptr == NULL);
        m_ptr = ptr;
    }
	//##ModelId=44CF175800E1
    T* Detach()
    {
        T* t = m_ptr;
        m_ptr = NULL;
        return t;
    }
};

#endif  // __AUTOPTR_H__
